package org.example.seata.common.core.constant;

/**
 * 分布式锁 key
 *
 * @author hzq
 * @date 2021/11/18 15:15
 */
public interface LKC {

    /**
     * @return lockKey
     */
    String getLockKey(Object id);

    /*====================================Product====================================*/

    enum Product implements LKC {
        /**
         * 产品虚拟库存key
         */
        PRODUCT_VIRTUAL_INVENTORY("product.product_virtual_inventory.");

        private String lockKey;

        Product(String lockKey) {
            this.lockKey = lockKey;
        }

        @Override
        public String getLockKey(Object id) {
            return lockKey + id;
        }
    }

    /*====================================Order====================================*/

    enum Order implements LKC {
        /**
         * 订单状态
         */
        ORDER_STATUS("order.order_status.");

        private String lockKey;

        Order(String lockKey) {
            this.lockKey = lockKey;
        }

        @Override
        public String getLockKey(Object id) {
            return lockKey + id;
        }
    }

    /*====================================OrderPayInfo====================================*/

    enum OrderPayInfo implements LKC {
        /**
         * 支付回调
         */
        CALLBACK_TIME("order_pay_info.callback_time.");

        private String lockKey;

        OrderPayInfo(String lockKey) {
            this.lockKey = lockKey;
        }

        @Override
        public String getLockKey(Object id) {
            return lockKey + id;
        }
    }

    /*====================================Account====================================*/

    enum Account implements LKC {
        /**
         * 账户余额
         */
        ACCOUNT_BALANCE("account.account_balance.");

        private String lockKey;

        Account(String lockKey) {
            this.lockKey = lockKey;
        }

        @Override
        public String getLockKey(Object id) {
            return lockKey + id;
        }
    }

}
